<?php
/**
 * Created by PhpStorm.
 * User: THUNDEROBOT
 * Date: 2021/1/12
 * Time: 9:56
 */

namespace app\admin\model;


use think\Model;
use think\Request;
use think\Config;
class Teacher extends Model
{
    public function checkUser($t_name,$t_password){
        $data = $this -> field('id,t_username,t_password')->where('t_username',$t_name)->find();
        if(!empty($data)){
            $data = $data->toArray();
            if($data['t_password']!=$t_password){
                echo'密码错误';
            }else{
                return "{:url('admin/index/index')}";

            }
        }else{
            echo '用户不存在';
        }
    }

    public function teacher(){
        //查询
        $map = [];
        $request = Request::instance();
        //判断是否搜索用户名
        if($request->has("tnameS","get")){
            $tnameS = $request->get("tnameS");
            $map['t_name'] = ["LIKE","%".$tnameS."%"];
        }

        $data = $this->where($map)->order("id asc")->paginate(Config::get("page_count"),false,[
            "query" =>$request->get()
        ]);
//     $data = $this->select();
//        echo $this->getLastSql();
        return $data;

    }

    //修改信息
    public function editteacher($id){
        $map["id"] = ["IN","$id"];
        $data = $this->where($map)->find();
        return $data;
    }
    //提交修改信息
    public function doEditteacher($userData){
        $map = [
            "id" => $userData["id"],

        ];
        $data = [
            "t_password" => $userData["t_password"]
        ];
        $data =  $this->where($map)->update($data);
//        echo $this->getLastSql();
        return $data;
    }

}